import React, { Component } from 'react'
import { Menu, Dropdown } from 'antd'
import { withRouter } from "react-router";
import styles from './index.less'
import { Layout } from 'antd';
const { Header } = Layout;

class MyHeader extends Component {
    signOut=()=>{
        localStorage.clear()
        this.props.history.replace('/login')
    }

    getUser = ()=>{
        const user = localStorage.account
        if(user){
            return user
        }else{
            this.props.history.replace('/login')
        }
    }

    render() {
        const menu = (
            <Menu>
                <Menu.Item onClick={this.signOut}>退出登录</Menu.Item>
            </Menu>
        )
        return (
            <Header className={`${styles.header} clearFix`}>
                <Dropdown className={`${styles.user} float-right`} overlay={menu}>
                    <span>{this.getUser()}</span>
                </Dropdown>
            </Header>
        )
    }
}

export default withRouter(MyHeader)
